
<table><tr><td>
<div class="code playground" contenteditable="true" spellcheck="false" autocomplete="off">
<pre style="display: none"><span>// +build OMIT

package main

import (
	"fmt"
	"math/rand"
	"time"
)

func calc(ch chan int) {
	rand.Seed(time.Now().Unix())
	val := rand.Intn(5)
	time.Sleep(time.Duration(val) * time.Microsecond)
	ch &lt;- val
}

</span></pre>

<pre><span num="18">func main() {</span>
<span num="19">    ch1, ch2 := make(chan int), make(chan int)</span>
<span num="20">    go calc(ch1)</span>
<span num="21">    go calc(ch2)</span>
<span num="22">    select {</span>
<span num="23">    case ans := &lt;-ch1:</span>
<span num="24">        fmt.Println("Answer from ch1: ", ans)</span>
<span num="25">    case ans := &lt;-ch2:</span>
<span num="26">        fmt.Println("Answer from ch2: ", ans)</span>
<span num="27">    }</span>
<span num="28">}</span>
</pre>

</div>
</td><td>
<div class="image"><img src="conf-cc-2016/select-cfsm.png"></div>
</td></tr></table>
